# 1. 从pymysql中导入connect函数
from unittest import result

from pymysql import connect,cursors

USERNAME = 'root'
PASSWORD = 'jisuanji2022'
HOST = '121.196.166.117'
PORT = 3306
DATABASE = 'woniunote'

def query_data(sql_str):
    try:
        # 链接数据库
        conn = connect(user=USERNAME, password=PASSWORD, host=HOST, port=PORT, database=DATABASE)

        # 获取游标对象cursor
        cur = conn.cursor(cursors.DictCursor)

        # 使用游标对象来执行SQL语句
        row_count = cur.execute(sql_str)

        # 提交修改数据的SQL语句到数据库
        conn.commit()

        # 使用游标对象获取查询结果
        result = cur.fetchall()

    except Exception as e:
       print(e)

    finally:

       cur.close()

       conn.close()

       return result